package com.wty.cmims.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wty.cmims.pojo.Code;
import com.wty.cmims.pojo.HealthRecord;
import com.wty.cmims.pojo.ResponseResult;
import com.wty.cmims.service.HealthRecordService;
import com.wty.cmims.mapper.HealthRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

/**
* @author wty
* @description 针对表【health_record】的数据库操作Service实现
* @createDate 2024-11-10 21:03:42
*/
@Service
public class HealthRecordServiceImpl extends ServiceImpl<HealthRecordMapper, HealthRecord>
    implements HealthRecordService{
    @Autowired
    private HealthRecordMapper healthRecordMapper;
    @Override
    public ResponseResult<Map<String, Object>> healthRecordFindById(Integer id) {
        ResponseResult<Map<String, Object>> responseResult = new ResponseResult<>();
        Map<String, Object> map = healthRecordMapper.findResidentHealthRecordById(id);
        SimpleDateFormat sdfDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            map.put("created_time", sdfDateTime.format(sdfDateTime.parse(map.get("created_time").toString())));
            map.put("updated_time", sdfDateTime.format(sdfDateTime.parse(map.get("updated_time").toString())));
            responseResult.setCode(Code.SUCCESS);
            responseResult.setMessage("查询居民健康档案成功");
            responseResult.setData(map);
        } catch (Exception e) {
            System.out.println("日期转换错误");
            responseResult.setCode(Code.ERROR);
            responseResult.setMessage("查询居民健康档案失败");
        }
        return responseResult;
    }
}




